#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:jidi
@file:main_page.py
@time:2022/08/29
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from web.wework.framework.base_page import BasePage
from web.wework.page.contract_page import ContactPage


class MainPage(BasePage):
    def __init__(self, driver=None):
        super().__init__(driver)
        self.driver.get('https://work.weixin.qq.com/wework_admin/frame#index')

    def contact(self):
        def loop_click(driver):
            self.click(By.LINK_TEXT, '通讯录')
            return len(self.driver.find_elements(By.LINK_TEXT, '删除')) > 0

        WebDriverWait(self.driver, 10).until(loop_click)

        return ContactPage(self.driver)

    def portal(self):
        self.click(By.LINK_TEXT, '首页')
        # self.driver.find_element(By.LINK_TEXT, '首页').click()
        return self
